/**
 * @Author：ming
 * @Date：2023/9/27 5:30 PM
 * @Filename：Lc3
 */

import java.util.ArrayList;

/**
 * @author ming
 */
public class Lc3 {
    public int lengthOfLongestSubstring(String s) {
        ArrayList<Character> list = new ArrayList<>();
        int max = 0;
        for (int i = 0; i < s.length(); i++) {
            Character c= s.charAt(i);
            if(list.contains(c)){
                int index = list.indexOf(c);
                for (int j = 0; j <= index; j++) {
                    list.remove(0);
                }
            }
            list.add(c);
            if(list.size()>max){
                max = list.size();
            }
        }

        return max;
    }
}
